package com.shop.admin.controller;

import com.shop.admin.result.ApiResult;
import com.shop.admin.service.PostService;
import com.shop.admin.utils.PageUtils;
import com.shop.admin.vo.PostToExamineVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

@Api(tags = {"PostController"},description = "学校表白墙接口")
@RestController
@RequestMapping("/api/post")
public class PostController {

    @Resource
    private PostService postService;

    @GetMapping("/list")
    @ApiOperation(value = "获取未置顶帖子列表",notes = "page,limit,orgId(条件查询)")
    public ApiResult postList(@RequestParam Map<String, Object> params){
        PageUtils page = postService.postList(params);
        return ApiResult.ok(page);
    }

    @GetMapping("/top/list")
    @ApiOperation(value ="获取置顶帖子列表",notes = "page,limit,orgId(条件查询)")
    public ApiResult postTopList(@RequestParam Map<String, Object> params){
        PageUtils page = postService.postTopList(params);
        return ApiResult.ok(page);
    }

    @PostMapping("/top/save")
    @ApiOperation(value = "置顶帖子顺序保存",notes = "帖子id数组")
    public ApiResult topPostSave(@ApiParam("参数为：postIds[]") @RequestBody Long[] ids){
        postService.topPostSave(Arrays.asList(ids));
        return ApiResult.ok("操作成功！");
    }

    @PostMapping("/top/delete")
    @ApiOperation(value = "取消帖子置顶",notes = "帖子id数组")
    public ApiResult topPostDelete(@ApiParam("参数为：postIds[]") @RequestBody Long[] ids){
        postService.topPostDelete(Arrays.asList(ids));
        return ApiResult.ok("操作成功！");

    }
    @GetMapping("/comment/list")
    @ApiOperation(value = "获取帖子评论列表",notes = "page,limit,postId")
    public ApiResult commentList(@RequestParam Map<String, Object> params){
        PageUtils page = postService.commentList(params);
        return ApiResult.ok(page);
    }

//    @GetMapping("/examine/list")
//    @ApiOperation(value = "获取审核帖子列表",notes = "page,limit,orgId(条件查询)")
//    public ApiResult postToExamineList(@RequestParam Map<String, Object> params){
//        PageUtils page = postService.postToExamineList(params);
//        return ApiResult.ok(page);
//    }

    @PostMapping("/to/examine")
    @ApiOperation(value = "审核修改状态",notes = "page,limit,postId,status(2发布已审核，3发布审核不通过)")
    public ApiResult toExamine(@RequestBody PostToExamineVo vo){
        postService.toExamine(vo);
        return ApiResult.ok("审核成功");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "帖子删除",notes = "传递数组")
    public ApiResult deletePost(@RequestBody Long[] ids){
        postService.deletePost(Arrays.asList(ids));
        return ApiResult.ok("帖子删除成功");
    }

    @PostMapping("/delete/comment")
    @ApiOperation(value = "帖子评论删除",notes = "传递数组")
    public ApiResult deletePostComment(@RequestBody Long[] ids){
        postService.deletePostComment(Arrays.asList(ids));
        return ApiResult.ok("评论删除成功");
    }
}
